package com.mg.operating.controller;

import com.mg.common.vo.ResponseResult;
import com.mg.operating.entity.ConfirmVo;
import com.mg.operating.entity.TotalVo;
import com.mg.operating.entity.VideoManage;
import com.mg.operating.service.VideoManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/manage")
public class ManageController {

    @Resource
    VideoManageService videoManageService;

    /**
     * 获取频信息与其相关的评论信息
     * @param id
     * @return
     */
    @GetMapping("/getvideo")
    public ResponseResult getVideo(@RequestParam int id){
        VideoManage video = videoManageService.getVideo(id);
        if (video==null){
            return ResponseResult.error();
        }
        return ResponseResult.ok(video);
    }

    /**
     * 视频转发数
     * @param id
     * @param confirm
     * @return
     */
    @GetMapping("/forWardplus")
    public ResponseResult forWardPlus(@RequestParam int id,@RequestParam int confirm){
        ConfirmVo confirmVo = videoManageService.forWardPlus(id, confirm);
        if (confirmVo==null){
            return ResponseResult.error();
        }
        return ResponseResult.ok(confirmVo);
    }

    /**
     * 添加点赞数
     * @param id
     * @return
     */
    @GetMapping("/like")
    public ResponseResult like(int id){
        int like = videoManageService.like(id);
        if (like==0){
            return ResponseResult.error();
        }
        return ResponseResult.ok();
    }

    /**
     * 删除视频及相关信息
     * @param id
     * @return
     */
    @GetMapping("/delvideo")
    public ResponseResult delVideo(int id){
        int delete = videoManageService.delete(id);
        if (delete==0){
            return ResponseResult.error();
        }
        return ResponseResult.ok();
    }

    /**
     * 统计视频总数，点赞总数，评论总数，转发总数
     * @return
     */
    @GetMapping("/count")
    public ResponseResult count(){
        TotalVo count = videoManageService.count();
        if (count==null){
            return ResponseResult.error();
        }
        return ResponseResult.ok(count);
    }
}
